//
//  DCMineViewController.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/11/28.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCMineViewController.h"
#import "DCMineTableViewCell.h"
#import "DCPersonMsgViewController.h"
#import "DCPersonIDCardViewController.h"
@interface DCMineViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UIView *firstView;
@property (nonatomic,strong) UIView *secondView;
@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) NSArray *titleArray;
@property (nonatomic,strong) NSArray *subTitleArray;
@property (nonatomic,strong) NSArray *imageArray;
@end

@implementation DCMineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.titleArray = @[@"资料认证",@"账单统计",@"违章查询",@"联系客服",@"常用路线",@"合作伙伴",@"维修管理",@"收款付款"];
    self.subTitleArray = @[@"已认证",@"查看订单对应的账单",@"查询车辆违章信息",@"400 100 8888",@"维护常用路线",@"合作伙伴维护及查看",@"审核司机上报的维修信息",@"查看收款流水、向外付款"];
    self.imageArray = @[@"mine_盾牌",@"mine_账单",@"mine_违章",@"mine_客服",@"mine_路线",@"mine_合作",@"mine_维修",@"mine_美元"];
    
    [self setUpUI];
    [self.view addSubview:self.tableView];
}
-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.secondView.bottom+10, ScreenWidth, 40*self.titleArray.count) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = NO;
        [_tableView setSeparatorInset:UIEdgeInsetsMake(0, 46, 0, 0)];//设置分割线
    }
    return _tableView;
}
-(void)setUpUI {
    
    __weak typeof(self) weakself = self;
    self.firstView = [[UIView alloc]initWithFrame:CGRectMake(0, 3, ScreenWidth, 80*HEIGHTSCALE6)];
    self.firstView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.firstView];
    
    UIImageView *personImage = [[UIImageView alloc]init];
    personImage.height = self.firstView.height - 20;
    personImage.width = personImage.height;
    personImage.x = 30;
    personImage.y = 10;
    //    personImage.backgroundColor = [UIColor redColor];
    personImage.image = IMAGENAME(@"个人头像");
    personImage.layer.cornerRadius = personImage.width /2;
    [self.firstView addSubview:personImage];
    
    UIImageView *pointImageView = [[UIImageView alloc]initWithImage:IMAGENAME(@"箭头")];
    [self.firstView addSubview:pointImageView];
    [pointImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakself.firstView.mas_right).offset(-10);
        make.width.mas_offset(20);
        make.height.mas_offset(20);
        make.centerY.equalTo(weakself.firstView);
    }];
    
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.text = Str_IsEmpty([UserInfo shareInstance].record.name)?@"xx运输公司":[UserInfo shareInstance].record.name;
    //    nameLabel.backgroundColor = [UIColor cyanColor];
    [self.firstView addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(personImage.mas_right).offset(10);
        make.right.equalTo(pointImageView.mas_left).offset(-10);
        make.top.equalTo(weakself.firstView.mas_top).offset(10);
        make.height.mas_offset(personImage.height/2);
    }];
    
    UILabel *phoneLabel = [[UILabel alloc]init];
    phoneLabel.text = Str_IsEmpty([UserInfo shareInstance].record.tel)?@"15012345678":[UserInfo shareInstance].record.tel;
    [self.firstView addSubview:phoneLabel];
    [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(personImage.mas_right).offset(10);
        make.right.equalTo(pointImageView.mas_left).offset(-10);
        make.top.equalTo(nameLabel.mas_bottom);
        make.height.mas_offset(personImage.height/2);
    }];
    
    UIButton *firstBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    firstBtn.frame = self.firstView.bounds;
    firstBtn.backgroundColor = [UIColor clearColor];
    [firstBtn addTarget:self action:@selector(firstBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    [self.firstView addSubview:firstBtn];
    
    self.secondView = [[UIView alloc]initWithFrame:CGRectMake(0, self.firstView.bottom+10, ScreenWidth, 80*HEIGHTSCALE6)];
    self.secondView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.secondView];
    
    UIView *carNum = [self getViewWithFrame:CGRectMake(0, 0, self.secondView.width/3, self.secondView.height) num:@"300" title:@"轿运车数量(台)"];
    [self.secondView addSubview:carNum];
    
    UIView *driverNum = [self getViewWithFrame:CGRectMake(carNum.right, 0, self.secondView.width/3, self.secondView.height) num:@"400" title:@"司机数量(人)"];
    [self.secondView addSubview:driverNum];
    
    UIView *transportNum = [self getViewWithFrame:CGRectMake(driverNum.right, 0, self.secondView.width/3, self.secondView.height) num:@"21468" title:@"运输车辆(台)"];
    [self.secondView addSubview:transportNum];
    
  
    
    CGFloat thirdHeight = ViewHeight - self.firstView.height - self.secondView.height - 13 - 10 - 10;
    UIView *thirdView = [[UIView alloc]initWithFrame:CGRectMake(0, self.secondView.bottom+10, ScreenWidth, thirdHeight)];
    //    thirdView.backgroundColor = [UIColor redColor];
    [self.view addSubview:thirdView];
}
-(void)firstBtnDidClick {
    DCPersonMsgViewController *personMsgVC = [[DCPersonMsgViewController alloc]init];
    [self.navigationController pushViewController:personMsgVC animated:YES];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.titleArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DCMineTableViewCell *cell = [DCMineTableViewCell cellWithTableView:tableView];
    if (indexPath.row == 3) {
        cell.subLabel.textColor = BlueColor;
        cell.pointImage.hidden = YES;
    }
    cell.titleImageView.image = IMAGENAME(self.imageArray[indexPath.row]);
    cell.titleLabel.text = self.titleArray[indexPath.row];
    cell.subLabel.text = self.subTitleArray[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {
        DCPersonIDCardViewController *IDCard = [[DCPersonIDCardViewController alloc]init];
        [self.navigationController pushViewController:IDCard animated:YES];
    }else if (indexPath.row == 3){
        [self callTelPhone];
    }
}

-(UIView *)getViewWithFrame:(CGRect)frame num:(NSString *)num title:(NSString *)title {
    UIView *view = [[UIView alloc]initWithFrame:frame];
    UILabel *numLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, view.width, view.height/2+10)];
    numLabel.text = num;
    numLabel.textColor = [UIColor redColor];
    numLabel.font = FONT(19);
    numLabel.textAlignment = NSTextAlignmentCenter;
    [view addSubview:numLabel];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, numLabel.bottom, view.width, view.height-numLabel.height)];
    titleLabel.text = title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = [UIColor lightGrayColor];
    titleLabel.font = FONT(14);
    [view addSubview:titleLabel];
    
    return view;
}
-(void)callTelPhone {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否联系客服" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        [DCTool call:@"4001008888"];
    }];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertVC addAction:sureAction];
    [alertVC addAction:cancleAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
